package work1
// 2：将一个正整数分解质因数。例如：输入90,打印出90=2*3*3*5。17=17
import scala.io.StdIn.readLine

object PrimeFactorization {
  def main(args: Array[String]): Unit = {
    print("请输入一个正整数：")
    val num = readLine().toInt
    println(s"$num = ${factorize(num).mkString("*")}")
  }

  def factorize(n: Int): List[Int] = {
    var number = n
    var factors = List[Int]()
    var divisor = 2
    while (number > 1) {
      while (number % divisor == 0) {
        factors = factors :+ divisor
        number /= divisor
      }
      divisor += 1
    }
    factors
  }
}